//
// Created by fangp on 3/6/18.
//


#include "runner_engine.h"
#include "../../src/ds/string.h"
#include "../../src/fa/statement.h"
#include "../../src/trans/parser.h"
#include "../../src/engine/fpengine.h"

static void test_extract() {
    Statement *statement = parse("{a}");
    String result = extract(statement);
    assert_string_equal(result, "a");
    statement = parse("{a b c}");
    result = extract(statement);
    assert_string_equal(result, "a b c");
    statement = parse("{a \"b\" c}");
    result = extract(statement);
    assert_string_equal(result, "a \"b\" c");
}


static void test_arglist() {
    Statement *statement = parse("{the arg is {a} and {b} and {c}}");
    String result = arglist(statement);
    assert_string_equal(result, "a b c");
    statement = parse("{ {a} { b } {c}}");
    result = arglist(statement);
    assert_string_equal(result, "a b c");
}


static void test_target() {
    Statement *statement = parse("{the target is {a} and {b} and {c}}");
    String result = target(statement);
    assert_string_equal(result, "{a} {b} {c}");
}


static void test_funcname() {
    Statement *statement = parse("{(or {x} {y})}");
    String result = funcname(statement);
    assert_string_equal(result, "or");
    statement = parse("{ ( or {x} {y} ) }");
    result = funcname(statement);
    assert_string_equal(result, "or");
}

//please refer to test_match_internal for test_match

int main(int argc, char **argv) {
    const struct CMUnitTest tests[] = {
            cmocka_unit_test(test_extract),
            cmocka_unit_test(test_arglist),
            cmocka_unit_test(test_target),
            cmocka_unit_test(test_funcname),
    };
    return cmocka_run_group_tests(tests, NULL, NULL);
}
